<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<c:set var="basePageTitle" value="${sessionScope.logoName}"	scope="request" />
<title>${logoName}</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta name="description" content="User login page" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<c:set var="baseURL" value="http://${header.host}${pageContext.request.contextPath}" scope="request" />
<script type="text/javascript">
	var baseURL = "${baseURL}";
</script>
<link rel="stylesheet" href="${baseURL}/web/css/style.css" />
<link href="${baseURL}/themes/blue/css/fonts/iconfont.css" rel="stylesheet" type="text/css" />
<LINK href="logo.png?v=1" type="image/x-icon" rel="shortcut icon" />
<script src="${baseURL}/js/jquerys/jquery-1.12.1.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/placeholder_IE.js" type="text/javascript"></script>
<%-- <script type="text/javascript" src="${baseURL}/themes/plugin/crypto-js/core.js"></script>
<script type="text/javascript" src="${baseURL}/themes/plugin/crypto-js/md5.js"></script> --%>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/aes.js"></script>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/pad-iso10126-min.js"></script>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/aesUtil.js"></script>
	<style>
	.logo h1{
    font-size: 40px;
    font-weight: bold;
    letter-spacing: 4px;
    color: #fff;
    margin-left: 40px;
	}

    <c:if test="${openRegister == 1 && isVerify == 1}">
    .login-content>.login-form {
        height: 410px;
    }
    .login-content {
        height: 410px;
    }
    </c:if>
	</style>
</head>
<body>
	<div class="container">
		<div class="logo">
				<c:choose>
					<c:when test="${!empty systemName}">
				 		<h1>${systemName}</h1>
				 	</c:when>
				 	<c:when test="${!empty loginLogo}">
				 		<img src='${baseURL}/cfg/basedefineedit/downloadImgCache.do?tempId=${loginLogo}' />
				 	</c:when>
				 	 
				 	<c:otherwise >
				 		<img src="${baseURL}/images/index/logo.png" />
 				 	</c:otherwise>
				</c:choose>
			
		</div>
	 
		<div class="login-content">
			<div class="login-form">
				<div class="title">用户登录</div>
				<form action="${baseURL}/system/security/logon/login.do" method="post" id="loginFormId"<!--  onsubmit="return enCode(); -->" ><!-- onsubmit="return enCode();" --> 
					<div class="form-input">
						<span class="icon"><i class="icon iconfont icon-icon-user"></i></span>
						<!-- <input type="text" id="username" name="username" placeholder="输入用户名" /> -->
						<input type="hidden"  id="username" name="username"/> 
						<input type="username" id="simpleUsername" name="simpleUsername" placeholder="输入用户名" />   
					</div>
					<div class="form-input">
						<span class="icon"><i class="icon iconfont icon-icon-unlock"></i></span>
						  <!-- 主要input需要放置最后,避免ie上无法兼容 -->
						  <input type="hidden"  id="password" name="password"   />   
					 	  <input type="password" id="simplePassword" name="simplePassword" placeholder="输入密码" />   
					</div>
					<c:if test="${isVerify == 1}">
					<div class="validate_code">
						<div class="form-input">
							<span class="icon"><i class="icon iconfont icon-icon-shield"></i></span>
							<input type="text" id="codes" name="codes" />
						</div>
						<span class="input-group-addon">
							<img class="validate_img" onclick="changeCode();" >
						</span>
					</div>
					</c:if>
					<span class="error-tip">
						<c:choose>
							<c:when test='${error==1}'>用户名或密码错误!</c:when>
							<c:when test='${error==2}'>该用户已被冻结,请重新登录!</c:when>
							<c:when test='${error==3}'>用户没有对应角色,不可登录系统!</c:when>
							<c:when test='${error==4}'>您输入的密码有误,您还剩[${lastTimes}]次机会!</c:when>
							<c:when test='${error==5}'>该用户今日登录次数已达上限!</c:when>
							<c:when test='${error==6}'>您已在其他地方登录!</c:when>
						</c:choose>
					</span>
					<div class="margin-20">
						<button type="button" class="blue-btn" id="submitForm">登录</button>
						<c:if test="${openRegister == 1}">
						<button type="button" class="blue-btn register-btn" style="margin-top: 10px;">注册</button>
						</c:if>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="footer">
		<p>
		<c:if test="${empty icp}">
		CopyRight©广州八斗软件科技有限公司  All Rights Reserved
		</c:if>
		<c:if test="${!empty icp}">
		${icp}
		</c:if>
		</p>
	</div>
	<script type="text/javascript">
	//浏览器识别
	function myBrowser() {
		var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
		var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
		//var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
		var isIE = !!window.ActiveXObject || "ActiveXObject" in window; //判断是否IE浏览器
		var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
		var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
		var isChrome = userAgent.indexOf("Chrome") > -1; //判断是否谷歌浏览器
		var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
		var is360 = userAgent.indexOf("360SE") > -1; //判断是否360浏览器
		var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
		if (isIE) {
			var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
			reIE.test(userAgent);
			var fIEVersion = parseFloat(RegExp["$1"]);
			//9.0以上才返回true
			if (fIEVersion >= 9) {
				return true;
			} else {
				//如果这里获取不到fIEVersion，证明是ie11,所以也返回true
				if (!fIEVersion)
					return true;
				return false;
			}
		}//isIE end
		if(isEdge){
			return true;
		}//isEdge end
		if (isFF) {
			return true;
		}
		/* if (isOpera) {
		    return true;
		} */
		if (isChrome) {
			return true;
		}
		if (is360) {
			return true;
		}
		if (isSafari) {
			return true;
		}
		return false;
	}//myBrowser() end

	//判断浏览器是否符合兼容性，不符合就跳转页面
	if (!myBrowser()) {
		window.location.href = "${baseURL}/change_browser.jsp";
	}
	
	function enCode(){
 	 	var password = document.getElementById("simplePassword").value;
 	 	var username = document.getElementById("simpleUsername").value;
		//document.getElementById("simplePassword").setAttribute("disabled", "disabled"); 
		//document.getElementById("simpleUsername").setAttribute("disabled", "disabled"); 
		document.getElementById("password").value=aesEncrypt(password);
		document.getElementById("username").value=aesEncrypt(username);
 	 }
	 
		$(function() {
			$(document).keypress(function(event) {
				if (event.keyCode == 13) { // 13表示回车键
					$("#submitForm").click();
					return false;
				}
			});
			changeCode();
			<c:if test="${!empty loginBackground}">
			$(".container").css("background","url(${baseURL}/cfg/basedefineedit/downloadImgCache.do?tempId=${loginBackground})")
			</c:if>


			// 注册按钮事件
			$('.register-btn').click(function () {
                window.location.href = "${baseURL}/system/security/userregister/register.do"
            })
		});

		/*登录验证*/
		$("#submitForm").click(function() {
			enCode();
			var name = $("#username").val();
			var pass = $("#password").val();
			var codes = $("#codes").val();
			
			if (name.trim() == "") {
				$(".error-tip").text("请输入用户名！");
				return false;
			}
			if (pass.trim() == "") {
				$(".error-tip").text("请输入密码！");
				return false;
			}
			if("${isVerify}"=="1"){
				if($.trim(codes) == ""){
					$(".error-tip").text("请输入验证码！");
					return false;
				}else{
					validateCode($("#codes"),$(".error-tip"),function(){
						if (name != "" && pass != "") {
							var Regx = /^[A-Za-z0-9]*$/;
							if (Regx.test(name)) {
								var formObj = document.getElementById("loginFormId");
								formObj.submit();
							} else {
								var formObj = document.getElementById("loginFormId");
								formObj.submit();
							}
						}
					});
				}
			}else{
				if (name != "" && pass != "") {
					var Regx = /^[A-Za-z0-9]*$/;
					if (Regx.test(name)) {
						var formObj = document.getElementById("loginFormId");
						formObj.submit();
					} else {
						var formObj = document.getElementById("loginFormId");
						formObj.submit();
					}
				}
			}
		});

		String.prototype.trim = function() {
			return this.replace(/(^\s+)|\s+$/g, "");
		}
		
		//点击图片更换验证码
		function changeCode(){
			$(".validate_img").attr("src","${baseURL}/validate/yzmcode/validate.do?date="+new Date())
		}
		
		function validateCode(obj,errorObj,callback){
			$.ajax({
				type: "post",
			 		async: true,
				url: "${baseURL}/validate/checkcode/checkCode.do",
				dataType:"json",
				data:{codes:$(obj).val()},
		        async: false,
		        success: function(data){
		        	if(data){
		        		if(data.hasOk){
		            		if(callback){
		            			callback();
		            		}
		        		}else{
		        			$(errorObj).text("验证码不正确！");
		            		return false;
		        		}
		        	}
		        }
		    });
		}
	</script>
</body>
</html>